package BanyuanClub.Work.Day0305;

import java.io.*;

public class SplitFile {
    public static void main(String[] args) {
        File file = new File("aaa.txt");
        try(BufferedInputStream bis1 = new BufferedInputStream
                (new FileInputStream("aaa.txt"));
            BufferedInputStream bis2 = new BufferedInputStream
                    (new FileInputStream("aaa.txt"));
            BufferedOutputStream bos1 = new BufferedOutputStream
                    (new FileOutputStream("aaa1.txt"));
            BufferedOutputStream bos2 = new BufferedOutputStream
                    (new FileOutputStream("aaa2.txt"))
        ){
            long lon = file.length();
            long before = lon/2;
            long after = before;
            byte[] by = new byte[8];
            while (before > 0){
                int in = bis1.read(by);
                bos1.write(by,0,(int) (before < in ? before : in));
                bos1.flush();
                before -= in;
            }
            bis2.skip(after);
            int in;
            while ((in = bis2.read(by)) != -1){
                bos2.write(by,0,in);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
